package com.yunbiao.ybbusstopplate.utils

import android.text.TextUtils
import com.blankj.utilcode.util.SPUtils
import com.yunbiao.ybbusstopplate.base.ContentValue

class SpTool {
    companion object {
        private const val SP_NAME = "ybbusstopplate"

        private const val APP_SERIAL_NUMBER = "app_serial_number"//设备序列号
        private const val CONFIG_APP_PATH = "config_app_path"//广告app
        private const val CONFIG_RESOURCE_PATH = "config_resource_path"//本地广告文件路径
        private const val CONFIG_SERIAL_PORT_TYPE = "config_serial_port_type"//报站器类型

        private const val CONFIG_SHOW_ADVERT = "config_show_advert"//显示广告区域
        private const val CONFIG_SHOW_LINE_TIME = "config_show_line_time"//显示首末班时间
        private const val CONFIG_SHOW_LINE_TYPE = "config_show_line_type"//线路展示方式 1：全屏 2：轮播

        private const val CONFIG_DOUBLE_SCREEN = "config_double_screen";

        private const val CONFIG_ADVERT_ISONLINE = "config_advert_isonline"//服务器是否是网络版
        private const val CONFIG_SERVER_ADDRESS = "config_server_address"//服务器地址
        private const val CONFIG_SERVER_PORT = "config_server_port"//服务器端口
        //缓存站点
        private const val LINE_NAME = "line_name"//线路名
        private const val SITE_START = "site_start"//开始站
        private const val SITE_END = "site_end"//终点站
        private const val SITE_LIST = "site_list"//站点列表
        private const val SITE_TIME="site_time"//首末班时间
        private const val SITE_START_TIME = "site_start_time"//起始站首末班时间 北京站;06:00,18:00
        private const val SITE_END_TIME = "site_end_time"//终点站时间 天通苑;06:10,18:00

        private const val LOG_TO_FILE = "log_to_file";//日志输出到文件

        private const val CONFIG_MAIN_SCREEN_ADDRESS = "config_main_screen_address";//主屏幕地址

        fun cleanSiteInfo() {
            getSPUtils().put(LINE_NAME, "")
            getSPUtils().put(SITE_START, "")
            getSPUtils().put(SITE_END, "")
            getSPUtils().put(SITE_LIST, "")
            getSPUtils().put(SITE_TIME,"")
            getSPUtils().put(SITE_START_TIME, "")
            getSPUtils().put(SITE_END_TIME, "")
        }

        private fun getSPUtils(): SPUtils {
            return SPUtils.getInstance(SP_NAME)
        }

        fun saveSiteStartTime(name: String, sTime: String, eTime: String) {
            if (TextUtils.isEmpty(name) || TextUtils.isEmpty(sTime) || TextUtils.isEmpty(eTime)) {
                getSPUtils().put(SITE_START_TIME, "")
                return
            }
            var s = name + ";" + sTime + "," + eTime
            getSPUtils().put(SITE_START_TIME, s)
        }

        fun getSiteStartTime(): String {
            return getSPUtils().getString(SITE_START_TIME, "")
        }

        fun saveSiteEndTime(name: String, sTime: String, eTime: String) {
            if (TextUtils.isEmpty(name) || TextUtils.isEmpty(sTime) || TextUtils.isEmpty(eTime)) {
                getSPUtils().put(SITE_END_TIME, "")
                return
            }
            var s = name + ";" + sTime + "," + eTime
            getSPUtils().put(SITE_END_TIME, s)
        }

        fun getSiteEndTime(): String {
            return getSPUtils().getString(SITE_END_TIME, "")
        }

        fun cleanSiteStartTime() {
            getSPUtils().put(SITE_START_TIME, "")
        }

        fun cleanSiteEndTime() {
            getSPUtils().put(SITE_END_TIME, "")
        }

        fun saveSiteTime(s1:String,e1:String,s2:String,e2:String){
            var ss=s1+","+e1+","+s2+","+e2
            getSPUtils().put(SITE_TIME,ss)
        }
//
        fun cleanSiteTime() {
            getSPUtils().put(SITE_TIME,"")
            getSPUtils().put(SITE_START_TIME, "")
            getSPUtils().put(SITE_END_TIME, "")
        }
//
        fun getSiteTime():List<String>?{
            val s = getSPUtils().getString(SITE_TIME, "")
            if (TextUtils.isEmpty(s)){
                return null
            }
            val list = s.split(",")
            return list
        }
        fun saveServerAddress(Address: String) {
            getSPUtils().put(CONFIG_SERVER_ADDRESS, Address)
        }

        fun getServerAddress(): String {
            return getSPUtils().getString(CONFIG_SERVER_ADDRESS, "")
        }
        fun saveServerPort(Port: String) {
            getSPUtils().put(CONFIG_SERVER_PORT, Port)
        }

        fun getServerPort(): String {
            return getSPUtils().getString(CONFIG_SERVER_PORT, "")
        }

        fun saveConfigAdvertServerType(status: Boolean) {
            getSPUtils().put(CONFIG_ADVERT_ISONLINE, status)
        }

        fun getConfigAdvertServerType(): Boolean {
            return getSPUtils().getBoolean(CONFIG_ADVERT_ISONLINE, false)
        }

        fun getLogToFile(): Boolean{
            return getSPUtils().getBoolean(LOG_TO_FILE,false);
        }

        fun saveLogToFile(b: Boolean) {
            getSPUtils().put(LOG_TO_FILE,b)
        }

        fun saveConfigShowAdvert(status: Boolean) {
            getSPUtils().put(CONFIG_SHOW_ADVERT, status)
        }

        fun getConfigShowAdvert(): Boolean {
            return getSPUtils().getBoolean(CONFIG_SHOW_ADVERT, false)
        }

        fun saveConfigShowLineTime(status: Boolean) {
            getSPUtils().put(CONFIG_SHOW_LINE_TIME, status)
        }

        fun getConfigShowLineTime(): Boolean {
            return getSPUtils().getBoolean(CONFIG_SHOW_LINE_TIME, true)
        }

        fun saveConfigShowLineType(type: Int) {
            getSPUtils().put(CONFIG_SHOW_LINE_TYPE, type)
        }

        fun getConfigShowLineType(): Int {
            return getSPUtils().getInt(CONFIG_SHOW_LINE_TYPE, 2)
        }

        //线路名
        fun save_line_name(line_name: String) {
            getSPUtils().put(LINE_NAME, line_name)
        }

        fun get_line_name(): String {
            return getSPUtils().getString(LINE_NAME, "")
        }

        fun save_site_start(site_start: String) {
            getSPUtils().put(SITE_START, site_start)
        }

        fun get_site_start(): String {
            return getSPUtils().getString(SITE_START, "")
        }

        fun save_site_end(site_end: String) {
            getSPUtils().put(SITE_END, site_end)
        }

        fun get_site_end(): String {
            return getSPUtils().getString(SITE_END, "")
        }

        fun save_site_list(site_list: String) {
            getSPUtils().put(SITE_LIST, site_list)
        }

        fun get_site_list(): String {
            return getSPUtils().getString(SITE_LIST, "")
        }


        //设备序列号
        fun saveAppSerialNumber(appSerialNumber: String) {
            getSPUtils().put(APP_SERIAL_NUMBER, appSerialNumber)
        }

        fun getAppSerialNumber(): String {
            return getSPUtils().getString(APP_SERIAL_NUMBER, "")
        }

        //广告app路径
        fun saveConfigAppPath(configAppPath: String) {
            getSPUtils().put(CONFIG_APP_PATH, configAppPath)
        }

        fun getConfigAppPath(): String {
            return getSPUtils().getString(CONFIG_APP_PATH, "")
        }

        //本地储存路径
        fun saveConfigResourcePath(configResourcePath: String) {
            getSPUtils().put(CONFIG_RESOURCE_PATH, configResourcePath)
        }

        fun getConfigResourcePath(): String {
            var path = getSPUtils().getString(CONFIG_RESOURCE_PATH, ContentValue.resoucePath)
            if (TextUtils.isEmpty(path)) {
                path = ContentValue.resoucePath
            }
            return path
        }

        fun getNewLocalAdvertCenterPath() :String{
            var path = "/guideBoardAPP/resource/advertLocalCenter"
            return path
        }

        fun getNewLocalAdvertBottomPath() :String{
            var path = "/guideBoardAPP/resource/advertLocalBottom"
            return path
        }

        //广播器类型
        fun saveConfigSerialPortType(portType: Int) {
            getSPUtils().put(CONFIG_SERIAL_PORT_TYPE, portType)
        }

        fun getConfigSerialPortType(): Int {
            return getSPUtils().getInt(CONFIG_SERIAL_PORT_TYPE, -1)
        }

        fun saveDoubleScreen(checked: Boolean) {
            getSPUtils().put(CONFIG_DOUBLE_SCREEN,checked);
        }

        fun getDoubleScreen(): Boolean {
            return getSPUtils().getBoolean(CONFIG_DOUBLE_SCREEN)
        }

        // 主屏幕地址
        fun saveMainScreenAddress(address: String) {
            getSPUtils().put(CONFIG_MAIN_SCREEN_ADDRESS, address)
        }

        fun getMainScreenAddress(): String{
            return getSPUtils().getString(CONFIG_MAIN_SCREEN_ADDRESS, "0.0.0.0")
        }
    }
}